﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BotonJXC.Entity;
using SupplierDAO = BotonJXC.DAO.SupplierDAO;
using BotonJXC.Util;
using NHibernate.Criterion;

namespace BotonJXC.BLL
{
   public class SupplierBLL : BaseBLL<SupplierDAO,Supplier,int>
    {
       public SupplierBLL()
       { }

       public PageModel<Supplier> Find(string supplierName, string supplierCode, string mnCode, int start, int count)
       {
           List<ICriterion> criterions = new List<ICriterion>();
           if (!string.IsNullOrEmpty(supplierName))
           {
               criterions.Add(Restrictions.Like("SupplierName", supplierName, MatchMode.Anywhere));
           }
           if (!string.IsNullOrEmpty(supplierCode))
           {
               criterions.Add(Restrictions.Eq("SupplierCode", supplierCode));
           }
           if (!string.IsNullOrEmpty(mnCode))
           {
               criterions.Add(Restrictions.Eq("MnCode", mnCode));
           }
           return Dao.FindByPage(criterions.ToArray(), null, start, count);
       }

       public Supplier FindSupplier( string supplierCode)
       {
               List<ICriterion> criterions = new List<ICriterion>();
               if (Utils.IsNotBlank(supplierCode)  )
            {
                criterions.Add(Restrictions.Eq("SupplierCode", supplierCode));
            }

               return Dao.FindUnique(criterions.ToArray());
       }

       public IList<Supplier> findSuppliers(Supplier su)
       {
           List<ICriterion> criterions = new List<ICriterion>();
           if (!string.IsNullOrEmpty(su.Enabled))
           {
               criterions.Add(Restrictions.Eq("Enabled", su.Enabled));
           }
           return Dao.Find(criterions.ToArray());
       }
    }
}
